/*
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.checks;

import java.util.ArrayList;

import com.onegravity.sudoku.solver.accumulator.HintsAccumulator;
import com.onegravity.sudoku.solver.accumulator.StopHintProductionException;
import com.onegravity.sudoku.solver.core.FinalHintProducer;
import com.onegravity.sudoku.solver.core.WarningHintProducer;
import com.onegravity.sudoku.solver.data.Cell;
import com.onegravity.sudoku.solver.data.Grid;

/**
 * This class checks that all set values are correct (compare to solution).
 * @author Emanuel Moecklin
 */
public class IncorrectDigitsProducer implements WarningHintProducer, FinalHintProducer {

	private Grid solvedGrid;
	private boolean detailedMessage;
	
	public IncorrectDigitsProducer(Grid solvedGrid, boolean detailedMessage) {
		this.solvedGrid = solvedGrid;
		this.detailedMessage = detailedMessage;
	}
	
	@Override
	public void getHints(Grid grid, HintsAccumulator accu) throws StopHintProductionException {
		if (solvedGrid==null) return;

		// collect incorrect cells
		ArrayList<Cell> result = new ArrayList<Cell>(); 
		for (int y=0; y<9; y++) {
			for (int x=0; x<9; x++) {
				int value = grid.getCellValue(x, y);
				int solution = solvedGrid.getCellValue(x, y);
				if (value!=0 && value!=solution) {
					result.add(grid.getCell(x, y));
				}
			}
		}
		
		if (result.size()>0) {
			IncorrectDigitsWarning message = new IncorrectDigitsWarning(grid, result, detailedMessage);
            accu.add(message);
		}
    }

    @Override
	public String getProducerName() {
		return null;
	}
}